<!DOCTYPE html>
<html lang="zh">
<head>
    <meta charset="UTF-8">
    <title>考研学校推荐</title>
    <style>
        body { font-family: Arial, sans-serif; }
        table { width: 100%; border-collapse: collapse; }
        th, td { border: 1px solid #ddd; padding: 8px; text-align: left; }
        th { background-color: #f2f2f2; }
    </style>
</head>
<body>
<h1>考研学校推荐</h1>
<form id="recommendationForm">
    <label for="schClass">选择专业:</label>
    <input type="text" id="schClass" name="schClass" value="计算机科学与技术" required>

    <label for="schoolProject">选择学校类型:</label>
    <select id="schoolProject" name="schoolProject">
        <option value="0">985</option>
        <option value="1">211</option>
        <option value="2">普通本科</option>
    </select>

    <button type="button" onclick="fetchRecommendations()">查询推荐学校</button>
</form>

<h2>推荐学校:</h2>
<table id="resultsTable">
    <thead>
    <tr>
        <th>学校名称</th>
        <th>学校所在地</th>
        <th>学校类型</th>
    </tr>
    </thead>
    <tbody>
    <!-- 结果将被动态插入 -->
    </tbody>
</table>

<script>
    function fetchRecommendations() {
        const schClass = document.getElementById('schClass').value;
        const schoolProject = document.getElementById('schoolProject').value;
        const apiURL = `http://localhost:8087/recommendations?schClass=${encodeURIComponent(schClass)}&schoolProject=${schoolProject}`;

        fetch(apiURL)
            .then(response => response.json())
            .then(data => {
                const table = document.getElementById('resultsTable').getElementsByTagName('tbody')[0];
                table.innerHTML = ''; // 清空表格

                data.forEach(item => {
                    let row = table.insertRow();
                    let cell1 = row.insertCell(0);
                    let cell2 = row.insertCell(1);
                    let cell3 = row.insertCell(2);

                    cell1.textContent = item.schoolName;
                    cell2.textContent = item.schoolArea;
                    cell3.textContent = item.schoolProject === '0' ? '985' : item.schoolProject === '1' ? '211' : '普通本科';
                });
            })
            .catch(error => console.error('Error fetching data:', error));
    }
</script>
</body>
</html>
